package com.zhaosc.spark.core.broadcast

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext

object BroadcastJoin {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local")
      .setAppName("BroadcastJoin");

    val sc = new SparkContext(conf);

    val nameList = Array(
      new Tuple2(1, "xuruyun"),
      new Tuple2(2, "liangyongqi"),
      new Tuple2(3, "wangfei"));

    val scoreList = Array(
      new Tuple2(1, 150),
      new Tuple2(2, 100))

    val nameBrodCast=sc.broadcast(nameList);
 
    val scoreRdd = sc.parallelize(scoreList);
    
    val nameRdd = sc.parallelize(nameBrodCast.value);
    
   // val broadCast=sc.broadcast(nameRdd);
    
    nameRdd.join(scoreRdd).collect().
    foreach(
        println( _))
    
    

    sc.stop();
  }
}